package de.justphil.tcg.tcgserver.websockets.messages;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class MessageSubject {
	public static final String GAME_JOIN		= "game-j";
	public static final String GAME_QUIT		= "game-q";
	public static final String GAME_PROGRESS	= "game-p";
	public static final String GAME_INFO		= "game-i";
	public static final String ERROR			= "err";
	
	public static boolean isSubject(String subject) {
		return subjects.containsKey(subject);
	}
	
	// These convenience methods are invoked after (!) the MessageParser has verified that
	// the received message's subject is one of the above specified subjects.
	// => Null/empty validation can be omitted!
	public static boolean isJoinSubject(TCGMessage msg) {
		return msg.getSubject().equals(GAME_JOIN);
	}
	
	public static boolean isQuitSubject(TCGMessage msg) {
		return msg.getSubject().equals(GAME_QUIT);
	}
	
	public static boolean isProgressSubject(TCGMessage msg) {
		return msg.getSubject().equals(GAME_PROGRESS);
	}
	
	public static boolean isInfoSubject(TCGMessage msg) {
		return msg.getSubject().equals(GAME_INFO);
	}
	
	private static final ConcurrentMap<String, Boolean> subjects = new ConcurrentHashMap<String, Boolean>();
	static {
		subjects.put(GAME_JOIN, true);
		subjects.put(GAME_QUIT, true);
		subjects.put(GAME_PROGRESS, true);
	}
}
